package com.hrt.web.product.dao.impl;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.GiftTypeDir;
import com.hrt.web.product.dao.GiftTypeDirWebDao;

@Repository
public class GiftTypeDirWebDaoImpl extends BaseDaoImpl<GiftTypeDir> implements GiftTypeDirWebDao{

	/**通过GiftTypeDir查找giftInfor的Id*/
	@SuppressWarnings({ "unchecked" })
	@Override
	public List<Long> findGiftBySonId(String sonIds) {
		Set<Long> set = new HashSet<Long>();

		List<Long> giftIdsList = new ArrayList<Long>();
		List<Long> giftIds = getHibernateTemplate().find("SELECT DISTINCT gtd.giftId FROM GiftTypeDir gtd WHERE gtd.giftType.isdelete=0 and gtd.typeId IN ("+sonIds+")");
		set.addAll(giftIds);
		List<Long> giftIdsPare = getHibernateTemplate().find("SELECT DISTINCT gtd.giftId FROM GiftTypeDir gtd WHERE gtd.giftType.isdelete=0 and gtd.giftType.parentId IN ("+sonIds+")");
		set.addAll(giftIdsPare);
		giftIdsList.addAll(set);
//		for(Long giftid : giftIdsList){
//			System.out.println("giftid==fffffff=>>>"+giftid);
//		}
		return giftIdsList;
	}
	
	/** 按是否删除查询	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftTypeDir> findDelAll() {
		
		return getHibernateTemplate().find("FROM GiftTypeDir WHERE isDelete=0");
	}

	/**根据礼品分类的ID找到礼品分类目录明细的列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftTypeDir> queryGiftTypeDirByGdId(Long typeId) {
		return this.getHibernateTemplate().find("FROM GiftTypeDir gitydir WHERE gitydir.isdelete=0 and gitydir.typeId = '"+typeId+"'");
	}
	
	/**根据礼品基本信息的ID找到礼品分类目录明细的列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftTypeDir> getGiftTypeDirByGIId(Long giftId) {
		return this.getHibernateTemplate().find("FROM GiftTypeDir gitydir WHERE gitydir.isdelete=0 and gitydir.giftId = '"+giftId+"'");
	}
}
